import {
  getNoticeList
} from '../../services/notice/index'
import {
  getAllNameList,
  getAllActiveById
} from '../../services/home/home'
import {
  getAllActivity
} from '../../services/activity/index'
const imgSrcList = [
  'https://jsgjzx.cn/prod-api/profile/upload/2024/04/wx/swiper1.jpg',
  'https://jsgjzx.cn/prod-api/profile/upload/2024/04/wx/swiper2.jpg',
  'https://jsgjzx.cn/prod-api/profile/upload/2024/04/wx/swiper3.jpg',
  'https://jsgjzx.cn/prod-api/profile/upload/2024/04/wx/swiper4.jpg',
  'https://jsgjzx.cn/prod-api/profile/upload/2024/04/wx/swiper5.jpg',
]
Page({
  data: {
    tabList: [],
    notice: [],
    list: [],
    imgSrcList,
    swiperImageProps: { mode: 'scaleToFill' },
    pageLoading: false,
    current: 1,
    autoplay: true,
    duration: '500',
    interval: 5000,
    navigation: { type: 'dots' },
  },

  onShow() {
    this.getTabBar().init();
  },

  onLoad() {
    this.init();
  },
  init() {
    this.loadHomePage();
    this.getAllNotice();
    this.getAllActivity();
  },
  getAllNotice() {
    getNoticeList().then(res => {
      if (res.data.code == 200) {
        this.setData({
          notice: (res.data.rows && res.data.rows.length > 0 ) ? res.data.rows[0] : {}
        })
      }
    })
  },
  getAllActivity() {
    getAllActivity().then(res => {
      if (res.data.code == 200) {
        this.setData({
          list: res.data.rows || []
        })
      }
      
    })
  },
  loadHomePage() {
    getAllNameList().then(res => {
      if (res.data.code == 200) {
        this.setData({
          tabList: (res.data.data || []).map(item => {
            return {
              text: item.name,
              key: item.association_id
            }
          })
        })
      }
    })
  },

  tabChangeHandle(e) {
    this.privateData.tabIndex = e.detail;
    this.loadActivitysList(true);
  },

  onReTry() {
    this.loadActivitysList();
  },

  async loadActivitysList(fresh = false) {
      const nextList = await getAllActiveById();
      this.setData({
        goodsList: nextList.data.rows,
      });
  },

  onClickCell (e) {
    const { id } = e.target.dataset
    if (!id) return;
    wx.navigateTo({
      url: `/pages/activityDetail/activityDetail?activityId=${id}`,
    });
  },
  navToActivityDetail(e) {
    const { id } = e.target.dataset
    if (!id) return;
    wx.navigateTo({
      url: `/pages/noticeDetail/index?noticeId=${id}`,
    });
  },
  
});